package com.example.sample.control;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.liteheaven.xblib.common.ui.DimensionUtil;

/**
 * 横向Name/Value配对布局
 */
public class NameValueLayout extends LinearLayout {

    private TextView tvName;
    private TextView tvValue;

    public NameValueLayout(Context context) {
        super(context);
        init();
    }

    public NameValueLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        init();
    }

    public NameValueLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init(){
        setOrientation(HORIZONTAL);

        //
        tvName = new TextView(getContext());
        LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        tvName.setLayoutParams(lp);
        addView(tvName);

        //
        View v = new TextView(getContext());
        lp = new LayoutParams(40, LayoutParams.MATCH_PARENT, 0.1f);
        v.setLayoutParams(lp);
        addView(v);

        //
        tvValue = new TextView(getContext());
        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        tvName.setLayoutParams(lp);
        tvValue.setMaxWidth(DimensionUtil.dip2px(getContext(), 160.0f));
        addView(tvValue);
    }

    public void setContent(String name, String value){
        tvName.setText(name);
        tvValue.setText(value);
    }
}
